package org.nf.box.web.controller;

import lombok.RequiredArgsConstructor;
import org.nf.box.common.result.ResultVO;
import org.nf.box.domain.PersonalInfo;
import org.nf.box.service.PersonalInfoService;
import org.nf.box.web.vo.PersonalInfoVO;
import org.springframework.web.bind.annotation.*;

/**
 * @Author lzp
 * @Date 2024-12-17
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/personal")
public class PersonalInfoController extends BaseController {

    private final PersonalInfoService personalInfoService;

    @GetMapping("/get")
    public ResultVO<PersonalInfo> getPersonalInfoById(@RequestParam("userId") int userId) {
        PersonalInfo personalInfoById = personalInfoService.getPersonalInfoById(userId);
        return success(personalInfoById);
    }

    @PostMapping("/update")
    public ResultVO<PersonalInfo> updatePersonalInfo(@RequestBody PersonalInfo personalInfo){
        personalInfoService.updatePointerInfo(personalInfo);
        ResultVO<PersonalInfo> vo = new ResultVO<>();
        vo.setCode(200);
        vo.setData(personalInfo);
        vo.setMessage("修改成功");
        return vo;
    }

    @GetMapping("/id")
    public ResultVO<PersonalInfoVO> getPersonalInfoVOById(@RequestParam("userId") int userId) {
        PersonalInfoVO personalInfoById = personalInfoService.getPointerInfoVOById(userId);
        return success(personalInfoById);
    }
}
